import { BaseWindow } from "../../../../component/window/BaseWindow";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GameConst } from "../../../../component/gconst/GameConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { LayerManager } from "../../../manager/LayerManager";
import { Cache } from "../../../cache/Cache";
import { RadioButtonGroup } from "../../../../../fl/controls/RadioButtonGroup";
import { PetExploreConfig } from "../../../resource/PetExploreConfig";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { EffectManager } from "../../../manager/EffectManager";
import { KeyBoardManager } from "../../../../../com/gengine/keyBoard/KeyBoardManager";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GRadioButton } from "../../../../../com/mui/controls/GRadioButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { SPetExploreInfo } from "../../../../../Message/Public/SPetExploreInfo";
type int = number;
//class PetExploreAutoAlertWindow
    
    export  class PetExploreAutoAlertWindow extends BaseWindow
    {
        constructor(arg1: Function=null)
        {
            super();
            this.setSize(300, 180);
            this.titleHeight = 28;
            this.title = Language.getString(54636);
            this._selFun = arg1;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._bg = ObjCreate.createBg(17, 39, 265, 130, this);
            ObjCreate.createTextField(Language.getString(54645), 25, 50, 200, 20, this);
            this._costTxt = ObjCreate.createTextField(GameConst.PetExploreAutoExploreCost.toString(), 85, 50, 200, 20, this, GlobalStyle.textFormat6);
            this._costTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._costBitmap = ObjCreate.createBitmap(ImagesConst.Tongqian_bind, 120, 49, this);
            this._tipTxt = ObjCreate.createTextField("", 25, 80, 200, 20, this);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.htmlText = Language.getString(54646);
            this._startBtn = ObjCreate.createGButton(Language.getString(54647), 120, 130, 70, 28, this);
            this._startBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onStartBtnClickHandler);
            return;
        }

        /* internal  */onStartBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=null;
            if (this._multiple > 1 && this._cost && (this._petExploreInfo == null || this._petExploreInfo && this._petExploreInfo.activeFactor <= 1)) 
            {
                loc1 = Alert.show(Language.getStringByParam(28033, this._cost[this._multiple - 2], this._multiple), null, Alert.OK | Alert.CANCEL, null, this.onClickHandler);
                LayerManager.highestLayer.addPopUp(loc1, true);
                LayerManager.highestLayer.centerPopup(loc1);
                return;
            }
            this.onClickHandler(Alert.OK);
            return;
        }

        /* internal  */onClickHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                this.hide();
                this._toSelect = true;
                if (this._selFun != null) 
                {
                    this._selFun(this._toSelect, this._multiple);
                }
            }
            return;
        }

        /* internal  */selectItem(arg1: Object /* flash.events.Event */): void
        {
            this._multiple = int(this._radioGroup.selectedData);
            return;
        }

        /* internal  */setActiveUI(): void
        {
            if (Cache.instance.petExplore.isActive) 
            {
                this.setSize(300, 240);
                this._bg.height = 189;
                if (this._activitySp == null) 
                {
                    this._activitySp = new Object /* flash.display.Sprite */();
                    ObjCreate.setObjAttri(this._activitySp, 0, 155, -1, -1, this);
                    this._singleCost = ObjCreate.createGTextField(Language.getString(28032), 50, 11, 220, 20, this._activitySp, null, true);
                    this._doubleCost = ObjCreate.createGTextField("", 50, 30, 220, 20, this._activitySp);
                    this._thrCost = ObjCreate.createGTextField("", 50, 50, 220, 20, this._activitySp);
                    this._radioGroup = new RadioButtonGroup("main");
                    this._radioGroup.addEventListener(flash.events.Event.CHANGE, this.selectItem);
                    this._singleBtn = ObjCreate.createRadioButton("", 32, 5, 100, 28, this._activitySp, "GCheckBox");
                    this._singleBtn.selected = true;
                    this._singleBtn.value = 1;
                    this._singleBtn.group = this._radioGroup;
                    this._doubleBtn = ObjCreate.createRadioButton("", 32, 25, 100, 28, this._activitySp, "GCheckBox");
                    this._doubleBtn.value = 2;
                    this._doubleBtn.group = this._radioGroup;
                    this._thrBtn = ObjCreate.createRadioButton("", 32, 45, 100, 28, this._activitySp, "GCheckBox");
                    this._thrBtn.value = 3;
                    this._thrBtn.group = this._radioGroup;
                }
                this._petExploreInfo = Cache.instance.petExplore.petExploreInfo;
                this._cost = PetExploreConfig.instance.getFactorCost(this._petExploreInfo);
                this._doubleCost.htmlText = Language.getStringByParam(28030, this._cost[0]);
                this._thrCost.htmlText = Language.getStringByParam(28031, this._cost[1]);
                if (this._petExploreInfo && this._petExploreInfo.activeFactor > 1) 
                {
                    this._multiple = this._petExploreInfo.activeFactor;
                    this._doubleBtn.enabled = false;
                    this._thrBtn.enabled = false;
                    if (this._petExploreInfo.activeFactor != 2) 
                    {
                        this._singleBtn.enabled = false;
                        this._doubleBtn.selected = false;
                        this._thrBtn.selected = true;
                    }
                    else 
                    {
                        this._doubleBtn.selected = true;
                        this._thrBtn.selected = false;
                        this._singleBtn.enabled = false;
                    }
                }
                else 
                {
                    this._singleBtn.enabled = true;
                    this._doubleBtn.enabled = true;
                    this._thrBtn.enabled = true;
                }
            }
            else 
            {
                this.setSize(300, 180);
                this._bg.height = 130;
                if (this._activitySp && this.contains(this._activitySp)) 
                {
                    DisplayUtil.removeMe(this._activitySp);
                    DisplayUtil.removeMe(this._singleBtn);
                    DisplayUtil.removeMe(this._doubleBtn);
                    DisplayUtil.removeMe(this._thrBtn);
                    DisplayUtil.removeMe(this._doubleCost);
                    DisplayUtil.removeMe(this._thrCost);
                    this._radioGroup.removeEventListener(flash.events.Event.CHANGE, this.selectItem);
                    this._radioGroup = null;
                    this._singleBtn = null;
                    this._doubleBtn = null;
                    this._thrBtn = null;
                    this._doubleCost = null;
                    this._thrCost = null;
                }
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            LayerManager.highestLayer.addPopUp(this, true);
            LayerManager.highestLayer.centerPopup(this);
            EffectManager.addUIMask([], 0);
            KeyBoardManager.instance.cancelListener();
            this._toSelect = false;
            this.setActiveUI();
            return;
        }

        public /* override */ hide(): void
        {
            LayerManager.highestLayer.removePopup(this);
            EffectManager.hideUIMask();
            KeyBoardManager.instance.addListener();
            if (this._selFun != null) 
            {
                this._selFun(this._toSelect, this._multiple);
            }
            return;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_costTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_costBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_startBtn: GButton;

        /* internal */ /* var */_selFun: Function;

        /* internal */ /* var */_toSelect: Boolean;

        /* internal */ /* var */_activitySp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_radioGroup: RadioButtonGroup;

        /* internal */ /* var */_singleBtn: GRadioButton;

        /* internal */ /* var */_doubleBtn: GRadioButton;

        /* internal */ /* var */_thrBtn: GRadioButton;

        /* internal */ /* var */_singleCost: GTextFiled;

        /* internal */ /* var */_doubleCost: GTextFiled;

        /* internal */ /* var */_thrCost: GTextFiled;

        /* internal */ /* var */_multiple: int=1;

        /* internal */ /* var */_petExploreInfo: SPetExploreInfo;

        /* internal */ /* var */_cost: Array<any>;
    }
